import { Menu, Dropdown, Icon,Checkbox} from 'antd';
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

export const getFields = () => {
  const labelcol = 5;
  const fieldcol = 15;
  let fields = [{
          domkey: ['templatename'],
          conditionType: 'input',
          label: getLabel(18151, '模板名称'),
          viewAttr: 3,
          rules: 'required|string'
      }, {
          domkey: ['templatetype'],
          conditionType: 'SELECT',
          label: getLabel(19471, '模板类型'),
          viewAttr: 3,
          options: [{ key: '0', showname: getLabel(83139, '私人模板'), selected: true }]
      },{
          domkey: ['displayorder'],
          conditionType: 'INPUTNUMBER',
          label: getLabel(88, '顺序'),
          viewAttr: 2,
          precision: 2,
      },{
        domkey: ['isdefault'],
        conditionType: 'CHECKBOX',
        label: getLabel(33731, '是否默认', 'label'),
        viewAttr: 2,
    },{
        domkey: ['id'],
        conditionType: 'input',
        label:'',
        viewAttr: 1,
        hide:true
    }].map(f => {
          return {
              ...f,
              labelcol,
              fieldcol
          }
      });
  return fields;
}



export const getColumns=(_this)=>{
    const getMenu =(id,templatename,templatetype,displayorder,isdefault)=>{
        return <Menu>
          <Menu.Item>
            <a onClick={()=>{
              _this.setTemplateCustomCondition(id);
            }}>{getLabel(83142, '查询条件定义', 'label')}</a>
          </Menu.Item>
          <Menu.Item>
            <a onClick={()=>{
              _this.setTemplateColumn(id);
            }}>{getLabel(84342, '查询条件字段定义', 'label')}</a>
          </Menu.Item>
          <Menu.Item>
            <a onClick={()=>{
              _this.edit(id,templatename,templatetype,displayorder,isdefault);
            }}>{getLabel(93, '编辑', 'label')}</a>
          </Menu.Item>
          <Menu.Item>
            <a onClick={()=>{
              _this.setDefault(id);
            }}>{getLabel(83144, '设置为默认', 'label')}</a>
          </Menu.Item>
          <Menu.Item>
            <a onClick={()=>{
              _this.delete(id);
            }}>{getLabel(91, '删除', 'label')}</a>
          </Menu.Item>
        </Menu>
    };
    const columns = [{
        title: getLabel(18151, '模板名称', 'label'),
        dataIndex: 'templatename',
        render:text=><a onClick={()=>{}}>{text}</a>,
        width:20,
      }, {
        title: getLabel(19471, '模板类型', 'label'),
        dataIndex: 'templatetypespan',
        width:10,
      },{
        title: getLabel(15513, '显示顺序', 'label'),
        dataIndex: 'displayorderspan',
        width:10,
      },{
        title: getLabel(33731, '是否默认', 'label'),
        dataIndex: 'isdefaultspan',
        width:10,
      }, {
        title: getLabel(882, '创建人', 'label'),
        dataIndex: 'createridspan',
        width:20,
      }, {
        title: getLabel(81517, '创建日期', 'label'),
        dataIndex: 'createdate',
        width:20,
      },{
        title: '',
        dataIndex: 'id',
        width:10,
        render:(id,record)=>
        <Dropdown overlay={getMenu(id,record.templatename,record.templatetype,record.displayorder,record.isdefault)}>
        <a className="ant-dropdown-link">
           {getLabel(104,"操作")}<Icon type="down" />
        </a>
      </Dropdown>
      }];
      return columns;
}


export const getColumnsSet = (checkAll) => {
  const columns=[{
    title: getLabel(31644,'字段名'), 
    dataIndex: 'fieldlabelname', 
    key: 'fieldlabelname', 
    com: [
        { label: '', type: 'TEXT' },
    ],
    colSpan: 1,
    width: '30%',
  },{
    title: <Checkbox onChange={key=>{
      let v=key.target.checked?'1':'0';
      checkAll(v);
  }}>{getLabel(15603,'是否显示')}</Checkbox>, 
    dataIndex: 'isshow', 
    key: 'isshow', 
    com: [
        { label: '', type: 'CHECKBOX',key:'isshow' },
    ],
    colSpan: 1,
    width: '30%',
  },{
    title: getLabel(23691,'字段排序'), 
    dataIndex: 'fieldorder', 
    key: 'fieldorder', 
    com: [
        { label: '', type: 'INPUT',key:'fieldorder'},
    ],
    colSpan: 1,
    width: '40%',
  }];
  return columns;
}